<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <style>
        * {
            padding: 0;
            margin: 0;
        }

        html {
            height: 5000px;
        }

        .box {
            width: 200px;
            height: 200px;
            background-color: #6ff;
            margin: 50px;
            padding: 10px;
            border: 1px solid #333;
            /* overflow: hidden; */
            overflow-y: scroll;
        }

        .sub {
            width: 100px;
            height: 1000px;
            background-color: pink;
        }
    </style>
</head>

<body>
    <div class="box">
        <div class="sub"></div>
    </div>
</body>
<script>
    // window.onresize = function () {
    //     console.log("文档的可视宽高", document.documentElement.clientWidth, document.documentElement.clientHeight);
    //     console.log("文档的实际宽高", document.documentElement.scrollWidth, document.documentElement.scrollHeight);
    // }
    // window.onscroll = function () {
    //     console.log("滚动条的位置", document.documentElement.scrollLeft, document.documentElement.scrollTop);
    // }

    var box = document.getElementsByClassName("box")[0];
    console.dir(box);

    // console.log(getStyle(box, "width"));
    // console.log(getStyle(box, "height"));

    // function getStyle(ele, key) {
    //     if (window.getComputedStyle) {
    //         return window.getComputedStyle(ele)[key];
    //     } else {
    //         return ele.currentStyle[key]
    //     }
    // }



    // clientWidth / clientHeight   元素的可视宽高 (content + padding)
    // offsetWidth / offsetHeight   元素的可视宽高 (content + padding + border)

    console.log("元素的可视宽高", box.clientWidth, box.clientHeight);
    // console.log("元素的可视宽高", box.offsetWidth, box.offsetHeight);
    console.log("元素的实际宽高", box.scrollWidth, box.scrollHeight);


    box.onscroll = function () {
        console.log("滚动条的位置", box.scrollLeft, box.scrollTop);
    }
</script>

</html>